<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        div{
            width: 400px;
            height: 400px;
            border: 1px solid darkgray;
        }
        img{
            width: 200px;
            height: 200px;
        }
    </style>
</head>
<body>
    <div>
        <button onclick="fn()">隐藏图片</button>
        <img src="./images/1.gif" alt="">
    </div>

    <script>
        var btn = document.querySelector('button');
        var img = document.querySelector('img');

        var flag = true;  // true => 图片显示   false图片隐藏

        function fn(){
            if(flag){  //图片处于显示状态 
                img.style.display = 'none';
                btn.innerHTML = '显示图片'
                flag = false;
            }else{  //图片处于隐藏状态 
                img.style.display = 'block';
                btn.innerHTML = '隐藏图片';
                flag = true;
            }

            // if(btn.innerHTML === '隐藏图片'){
            //     img.style.display = 'none';
            //     btn.innerHTML = '显示图片'

            // }else{
            //     img.style.display = 'block';
            //     btn.innerHTML = '隐藏图片';
            // }

        }
    </script>
</body>
</html>